import 'dart:ffi';

import 'package:get/get.dart';
import 'package:intl/intl.dart';
import 'package:my_meeting/utils/utils.dart';

import '../../../entity/meeting_data.dart';
import '../../../generated/l10n.dart';
import '../../../global.dart';
import '../../../utils/log_utils.dart';

class Metting_allLogic extends GetxController {

  var meetingList = <MeetingData>[].obs;

  var endMeetingList = <MeetingData>[].obs;

  var myMeetingList = <MeetingData>[].obs;

  @override
  void onInit() {
    // TODO: implement onInit
    super.onInit();
    refreshMeetings();
  }

  void refreshMeetings() {
    meetingList.clear();
    global.getMeetings().then((value) {
      // meetingList.assignAll(value);
      configMeetingList(value);
    });
  }

  void configMeetingList(List<MeetingData> meetingList){
    for(MeetingData data in meetingList){
      String state = Utils.meetingState(data);
      if(state == S.current.hadCancel || state == S.current.hadEnd){
        endMeetingList.add(data);
      }else{
        myMeetingList.add(data);
      }
    }
  }

  String getDisplayTitle(int index) {
    MeetingData data = meetingList[index];
    DateFormat format = DateFormat("yyyy.MM.dd"); // 根据字符串格式设置
    DateTime dateTime = format.parse(data.meetingBeginTime!);

    // 获取今天的日期
    DateTime today = DateTime.now();

    // 判断是否为今天
    bool isToday = dateTime.year == today.year &&
        dateTime.month == today.month &&
        dateTime.day == today.day;

    // 输出结果
    String formatDate = '${dateTime.month}月/${dateTime.day}日';
    if (isToday) {
      return '${S.current.today} | $formatDate';
    } else {
      return formatDate;
    }
  }

  @override
  void onReady() {
    // TODO: implement onReady
    super.onReady();
  }

}
